<?php

use app\common\enum\AppointmentStatus as StatusEnum;

?>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf"><?= $title ?></div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form id="form-search" class="toolbar-form" action="" autocomplete="off">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <input type="hidden" name="dataType" value="<?= $dataType ?>">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a class="am-btn am-btn-default am-btn-success am-radius"
                                               href="<?= url('appointment.order/add') ?>">
                                                <span class="am-icon-plus"></span> 新增
                                            </a>
                                        </div>
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a class="am-btn am-btn-default am-btn-success am-radius"
                                               href="<?= url('offline/add') ?>">
                                                <span class="am-icon-plus"></span> 新增线下订单
                                            </a>
                                        </div>
                                    </div>
                                    
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">
                                    <div class="am-form-group am-fl">
                                        <?php $status = $request->get('status'); ?>
                                        <select name="status"
                                                data-am-selected="{btnSize: 'sm', placeholder: '预约状态'}">
                                            <option value=""></option>
                                            <option value="-1"
                                                <?= $status === '-1' ? 'selected' : '' ?>>全部
                                            </option>
                                            <option value="-2"
                                                <?= $status === '-2' ? 'selected' : '' ?>>未指派
                                            </option>
                                            <option value="-3"
                                                <?= $status === '-3' ? 'selected' : '' ?>>已指派
                                            </option>
                                            <?php foreach (StatusEnum::data() as $item): ?>
                                                <option value="<?= $item['value'] ?>"
                                                    <?= $item['value'] == $status ? 'selected' : '' ?>><?= $item['name'] ?>
                                                </option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <?php $serviceId = $request->get('service_id'); ?>
                                        <select name="service_id"
                                                data-am-selected="{btnSize: 'sm', placeholder: '服务人员'}">
                                            <option value=""></option>
                                            <option value="-1"
                                                <?= $serviceId === '-1' ? 'selected' : '' ?>>全部
                                            </option>
                                            <?php if (isset($service_list)): foreach ($service_list as $item): ?>
                                                <option value="<?= $item['user_id'] ?>"
                                                    <?= $item['user_id'] == $serviceId ? 'selected' : '' ?>><?= $item['real_name'] ?>
                                                </option>
                                            <?php endforeach; endif; ?>
                                        </select>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="start_time"
                                               class="am-form-field"
                                               value="<?= $request->get('start_time') ?>" placeholder="请选择起始日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="end_time"
                                               class="am-form-field"
                                               value="<?= $request->get('end_time') ?>" placeholder="请选择截止日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入用户昵称/手机号/订单号" value="<?= $request->get('search') ?>">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search"
                                                        type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="order-list am-scrollable-horizontal am-u-sm-12 am-margin-top-xs">
                        <table width="100%" class="am-table am-table-centered
                         am-margin-bottom-xs" >
                            <thead>
                            <tr>
                                <th>订单ID</th>
                                <th>订单类型</th>
                                <th>客户信息</th>
                                <th>服务类型</th>
                                <th>服务价格</th>
                                <th>预约时间</th>
                                <th>服务人员</th>
                                <th>服务内容</th>
                                <th>服务数量</th>
                                <th>服务拍摄照片</th>
                                <th width="10%">服务评价</th>
                                <th width="10%">服务评价图片</th>
                                <th>是否收款</th>
                                <th>是否自建单</th>
                                <th>状态</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><?= $item['order_id'] ?></td>
                                    <td class="am-text-middle"><?= $item['is_offline_text'] ?></td>
                                    <td class="am-text-middle"><?= $item['user_name'] . '<br/>' . $item['user_phone'] . '<br/>' . $item['address'] ?></td>
                                    <td class="am-text-middle"><?= $item['type_name'] ?></td>
                                    <td class="am-text-middle"><?= $item['total_price'] ?></td>
                                    <td class="am-text-middle">
                                        <?php foreach ($item['time_name_arr'] as $it): ?>
                                            <?= $item['appointment_date_text'] . '' .  $it;?>
                                    <br>
                                        <?php  endforeach;  ?>

                                    </td>
                                    <td class="am-text-middle"><?= $item['service_name'] ?></td>
                                    <td class="am-text-middle"><?= $item['offline_name'] ?></td>
                                    <td class="am-text-middle"><?= $item['num'] ?></td>
                                    <td class="am-text-middle">
                                        <?php foreach ($item['images'] as $it): ?>
                                            <a href="<?= $it['image'] ?>"
                                               title="点击查看大图" target="_blank">
                                                <img src="<?= $it['image'] ?>"
                                                     width="50" height="50" alt="付款截图">
                                            </a>
                                        <?php  endforeach;  ?>
                                    </td>
                                    <td class="am-text-middle" style="width: 100px;">
                                        <?php if ($item['stars'] > 0): ?>
                                            <a><?= $item['ping']?></a>
                                        <?php endif; ?>
                                    </td>
                                    <td class="am-text-middle" style="width: 100px;">
                                        <?php foreach ($item['ping_img'] as $it): ?>
                                            <a href="<?= $it?>"
                                               title="点击查看大图" target="_blank">
                                                <img src="<?= $it ?>"
                                                     width="50" height="50" alt="付款截图">
                                            </a>
                                        <?php  endforeach;  ?>
                                    </td>
                                    <td class="am-text-middle"><?= $item['offline_pay_status'] ?></td>
                                    <td class="am-text-middle"><?= $item['is_self'] ?></td>
                                    <td class="am-text-middle"><?= $item['status_text'] ?></td>
                                    <td class="am-text-middle"><?= $item['create_time'] ?></td>
                                    <td class="am-text-middle">
                                        <?php if ($item['status'] == 1 && $item['iscancel'] == 0): ?>
                                            <div class="tpl-table-black-operation">
                                                <?php if ($item['is_offline'] == 0): ?>
                                                <?php if ($item['status'] == 1): ?>
                                                    <?php if (checkPrivilege('appointment.order/edit')): ?>
                                                        <a href="<?= url('appointment.order/edit',
                                                            ['order_id' => $item['order_id']]) ?>">
                                                            <i class="am-icon-pencil"></i> 编辑
                                                        </a>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                                <?php endif; ?>
                                                <?php if ($item['is_offline'] == 1 && $item['iscancel'] == 0): ?>
                                                    <?php if (checkPrivilege('appointment.time/edit')): ?>
                                                        <a class="tpl-table-black-operation-default"
                                                           href="<?= url('offline/edit', ['order_id' => $item['order_id']]) ?>">
                                                            <i class="am-icon-pencil"></i> 编辑
                                                        </a>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            </div>
                                        <?php endif; ?>

                                        <?php if ($item['iscancel'] == 1): ?>
                                            <a style="color: red"> 已取消 </a>
                                        <?php endif; ?>

                                        
                                        <button class="am-btn am-btn-xs journal" style="background:#fff;border:1px solid #ccc" data-id="<?= $item['id'] ?>" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0}">日志</button>
                                        <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
                                          <div class="am-modal-dialog">
                                            <div class="am-modal-hd">日志信息
                                              <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
                                            </div>
                                            <div class="am-modal-bd log_content">
                                               <!-- <div>2021-01-05 16:36:10 管理员操作上门人员，工作人员收到推送消息状态为:失败</div> -->
                                            </div>
                                          </div>
                                        </div>

                                    </td>
                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="9" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    $(function () {

        /**
         * 订单导出
         */
        $('.j-export').click(function () {
            var data = {};
            var formData = $('#form-search').serializeArray();
            $.each(formData, function () {
                this.name !== 's' && (data[this.name] = this.value);
            });
            window.location = "<?= url('order.operate/export') ?>" + '&' + $.urlEncode(data);
        });


        //获取日志信息
        $('.journal').click(function () {
          console.log(1111)
          let order_id = $(this).attr('data-id')
          console.log($(this).attr('data-id'))
          // window.location = "<?= url('order.operate/export') ?>" + '&' + $.urlEncode(data);
          $.ajax({
            type : "POST",
            contentType: "application/json;charset=UTF-8",
            url : "<?= url('appointment.order/orderRecord') ?>" + '&order_id=' + order_id,
            success:function(res){
              console.log(res.list)
              var html = ''
              var div = ''
              if(res.list.length == 0){
                $('.log_content').html('暂时没有日志信息')
              }else{
                for(let i = 0 ; i < res.list.length; i++){
                  // console.log(res.list[i])
                  div =  `<div style="text-align:left;margin:10px 20px">`+ res.list[i].create_time + `  ` +  res.list[i].info +`</div>`
                  html += div
                }
                $('.log_content').html(html)
              }
              
              
            }
          })
        })


    });

</script>

